package zero.tech.games.gate.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import zero.tech.core.data.PageBean;
import zero.tech.core.data.SimpleUser;
import zero.tech.games.common.data.RoomNode;
import zero.tech.games.entity.games.CfMarquee;
import zero.tech.games.entity.games.ClubMember;
import zero.tech.games.entity.games.ClubMemberPermission;
import zero.tech.games.entity.games.ClubMemberProxy;
import zero.tech.games.entity.games.ClubMemberRole;
import zero.tech.games.entity.games.Mail;
import zero.tech.games.entity.games.UserOnline;
import zero.tech.games.entity.user.TUser;
import zero.tech.games.entity.user.TUserAccount;
import zero.tech.games.gate.data.entity.ClubPipei;
import zero.tech.games.gate.data.entity.ZsMemberExt;
import zero.tech.games.gate.data.notify.NotifyBeKickoutClub;
import zero.tech.games.gate.data.notify.NotifyClubMemberChange;
import zero.tech.games.gate.data.notify.NotifyDiamondChange;
import zero.tech.games.gate.data.notify.NotifyEnterGame;
import zero.tech.games.gate.data.res.GateResLogin;
import zero.tech.games.gate.data.res.ResDirectMembers;
import zero.tech.games.gate.data.res.ResListMarquee;
import zero.tech.games.gate.data.res.ResLookClubMember;
import zero.tech.games.gate.data.res.ResLookUser;
import zero.tech.games.gate.data.res.ResMailList;
import zero.tech.games.gate.data.res.ResSelectHehuorenPermission;

public class PackageUtil {

	public static GateResLogin packageGateResLogin(SimpleUser simpleUser, TUserAccount account, ClubPipei clubPipei) {
		GateResLogin gateResLogin=new GateResLogin();
		gateResLogin.setAccount(account);
		gateResLogin.setSimpleUser(simpleUser);
		if(clubPipei!=null) {
			gateResLogin.setClub_pipei(clubPipei);
		}
		return gateResLogin;
	}

	public static ResLookUser packageResLookUser(TUser user, UserOnline userOnline) {
		ResLookUser resLookUser = new ResLookUser();
		resLookUser.setSimpleUser(packageSimpleUser(user));
		resLookUser.setRegist_time(user.getRegist_time());
		resLookUser.setOnline(userOnline!=null?userOnline.getOnline():0);
		return resLookUser;
	}

	private static SimpleUser packageSimpleUser(TUser user) {
		SimpleUser simpleUser = new SimpleUser();
		simpleUser.setAi(user.getAi());
		simpleUser.setHead_img(user.getHead_img());
		simpleUser.setIdno(user.getIdno());
		simpleUser.setNick(user.getNick());
		simpleUser.setSex(user.getSex());
		simpleUser.setUid(user.getUid());
		return simpleUser;
	}

	public static ResDirectMembers packageResDirectMembers(int total_size, int page, int pageLength, List<Integer> zsUids, Map<Integer, TUser> usermap,
			Map<Integer, ClubMember> clubmembermap, Map<Integer, ClubMemberRole> clubMemberRoleMap, long total_tea, Map<Integer, Integer> zs_count_map, Map<Integer, Integer> fzs_count_map, Map<Integer, ClubMemberProxy> clubMemberProxyMap, List<Integer> frozen_uids, Map<Integer, UserOnline> onlinemap) {
		ResDirectMembers resDirectMembers = new ResDirectMembers();
		List<ZsMemberExt> list=new ArrayList<>();
		for(Integer uid:zsUids) {
			TUser user=usermap.get(uid);
			ClubMember clubMember = clubmembermap.get(uid);
			ClubMemberRole clubMemberRole = clubMemberRoleMap.get(uid);
			ClubMemberProxy clubMemberProxy=clubMemberProxyMap.get(uid);
			UserOnline userOnline = onlinemap.get(uid);
			int zs_count=zs_count_map.get(uid);
			int fzs_count=fzs_count_map.get(uid);
			int frozen=frozen_uids.contains(uid)?1:0;
			int online=userOnline!=null?userOnline.getOnline():0;
			ZsMemberExt zsMemberExt = packageZsMemberExt(user, clubMember, clubMemberRole,clubMemberProxy,zs_count,fzs_count,frozen,online);
			list.add(zsMemberExt);
		}
		PageBean<ZsMemberExt> pageBean = new PageBean<>(total_size, pageLength, page, list);
		resDirectMembers.setPageBean(pageBean);
		resDirectMembers.setTotal_tea(total_tea);
		return resDirectMembers;
	}

	public static NotifyClubMemberChange packageNotifyClubMemberChange(ClubMember clubMember) {
		NotifyClubMemberChange notifyClubMemberChange = new NotifyClubMemberChange();
		notifyClubMemberChange.setClubMember(clubMember);
		return notifyClubMemberChange;
	}

	public static ResLookClubMember packageResLookClubMember(TUser user, ClubMember clubMember,
			ClubMemberRole clubMemberRole,ClubMemberProxy clubMemberProxy, Map<Integer, Integer> zs_count_map, Map<Integer, Integer> fzs_count_map, List<Integer> frozen_uids,UserOnline useronline) {
		ResLookClubMember resLookClubMember=new ResLookClubMember();
		int zs_count=zs_count_map.get(clubMember.getUid());
		int fzs_count=fzs_count_map.get(clubMember.getUid());
		int frozen=frozen_uids.contains(clubMember.getUid())?1:0;
		int online=useronline!=null?useronline.getOnline():0;
		resLookClubMember.setZsMemberExt(packageZsMemberExt(user,clubMember,clubMemberRole,clubMemberProxy,zs_count,fzs_count,frozen,online));
		return resLookClubMember;
	}

	private static ZsMemberExt packageZsMemberExt(TUser user, ClubMember clubMember,
			ClubMemberRole clubMemberRole, ClubMemberProxy clubMemberProxy, int zs_count, int fzs_count, int frozen, int online) {
		ZsMemberExt zsMemberExt = new ZsMemberExt();
		zsMemberExt.setSimpleUser(packageSimpleUser(user));
		zsMemberExt.setRole(clubMemberRole.getRole());
		zsMemberExt.setTea(clubMember.getTea());
		zsMemberExt.setSafety(clubMember.getSafety());
		zsMemberExt.setFrozen_gold(clubMember.getFrozen());
		zsMemberExt.setFanyong(clubMemberProxy.getFanyong());
		zsMemberExt.setFzs_count(fzs_count);
		zsMemberExt.setZs_count(zs_count);
		zsMemberExt.setFrozen(frozen);
		zsMemberExt.setOnline(online);
		return zsMemberExt;
	}

	public static ResSelectHehuorenPermission packageResSelectHehuorenPermission(
			ClubMemberPermission otherMemberPermission) {
		ResSelectHehuorenPermission resSelectHehuorenPermission = new ResSelectHehuorenPermission();
		resSelectHehuorenPermission.setClubMemberPermission(otherMemberPermission);
		return resSelectHehuorenPermission;
	}

	public static NotifyEnterGame packageNotifyEnterGame(RoomNode roomNode, int fzb_playernum) {
		NotifyEnterGame notifyEnterGame = new NotifyEnterGame();
		notifyEnterGame.setClub_id(Integer.valueOf(roomNode.getClub_id()));
		notifyEnterGame.setRoom_id(roomNode.getRoom_id());
		notifyEnterGame.setFzb_playernum(fzb_playernum);
		return notifyEnterGame;
	}

	public static ResListMarquee packageResListMarquee(List<CfMarquee> cfMarquees) {
		ResListMarquee resListMarquee = new ResListMarquee();
		resListMarquee.getList().addAll(cfMarquees);
		return resListMarquee;
	}

	public static ResMailList packageResMailList(PageBean<Mail> pageBean) {
		ResMailList resMailList = new ResMailList();
		resMailList.setPageBean(pageBean);
		return resMailList;
	}

	public static NotifyDiamondChange packageNotifyDiamondChange(TUserAccount userAccount) {
		NotifyDiamondChange notifyDiamondChange = new NotifyDiamondChange();
		notifyDiamondChange.setUserAccount(userAccount);
		return notifyDiamondChange;
	}

	public static NotifyBeKickoutClub packageNotifyBeKickoutClub(int club_id) {
		NotifyBeKickoutClub notifyBeKickoutClub = new NotifyBeKickoutClub();
		notifyBeKickoutClub.setClub_id(club_id);
		return notifyBeKickoutClub;
	}

}
